package com.example.photograph.controller;

import com.example.photograph.domain.AjaxResult;
import com.example.photograph.domain.SysBag;
import com.example.photograph.page.TableDataInfo;
import com.example.photograph.service.ISysBagService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐管理Controller
 * 
 * @author wuyj
 * @date 2021-03-06
 */
@Controller
@RequestMapping("/photograph/bag")
public class SysBagController extends BaseController
{
    private String prefix = "photograph/bag";

    @Autowired
    private ISysBagService sysBagService;

    @RequiresPermissions("photograph:bag:view")
    @GetMapping()
    public String bag()
    {
        return prefix + "/bag";
    }

    /**
     * 查询套餐管理列表
     */
    @RequiresPermissions("photograph:bag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysBag sysBag)
    {
        startPage();
        List<SysBag> list = sysBagService.selectSysBagList(sysBag);
        return getDataTable(list);
    }

    /**
     * 新增套餐管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存套餐管理
     */
    @RequiresPermissions("photograph:bag:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysBag sysBag)
    {
        return toAjax(sysBagService.insertSysBag(sysBag));
    }

    /**
     * 修改套餐管理
     */
    @GetMapping("/edit/{bagId}")
    public String edit(@PathVariable("bagId") Long bagId, ModelMap mmap)
    {
        SysBag sysBag = sysBagService.selectSysBagById(bagId);
        mmap.put("sysBag", sysBag);
        return prefix + "/edit";
    }

    /**
     * 修改保存套餐管理
     */
    @RequiresPermissions("photograph:bag:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysBag sysBag)
    {
        return toAjax(sysBagService.updateSysBag(sysBag));
    }

    /**
     * 删除套餐管理
     */
    @RequiresPermissions("photograph:bag:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysBagService.deleteSysBagByIds(ids));
    }
}
